<template>
	<view class="container">
		<uni-forms >
			<uni-forms-item label="姓名" name="name">
				<uni-easyinput type="text" v-model="telephone" placeholder="请输入姓名" />
			</uni-forms-item>
			<uni-forms-item label="密码" name="password">
				<uni-easyinput type="password" v-model="password" placeholder="请输入姓名" />
			</uni-forms-item>
		</uni-forms>
		<button @click="login" type='primary'>登录</button>
		<button @click="go" type="default" >注册</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				telephone:'',
				password:''
			}
		},
		methods: {
			go(){
				uni.navigateTo({
					url:'/pages/my/register/register'
				})
			},
			login(){
				console.log(this.password,this.telephone);
				uni.request({
					url: 'http://localhost:8090/foodapp/user/login',
					method: 'POST',
					data: {
						telephone:this.telephone,
						password:this.password
					},
					success: res => {
						if(res.data.success){
							uni.setStorage({
								key:'user',
								data: res.data.data,
								success: function () {
										console.log('success');
									}
							});
							// uni.setStorageSync('user', res.data.data);
						  uni.navigateBack({
							  delta:1
						  })
							
						}
					},
					fail: () => {},
					complete: () => {}
				});
			}
		},
		onLoad: () => {
			uni.onTabBarMidButtonTap(function(e) {
				console.log(e)

			})
		}
	}
</script>

<style>
	.container {
		padding: 20px;
		font-size: 14px;
		line-height: 24px;
	}
</style>
